package com.joven.core.conf;

import com.joven.core.constant.ZkProperties;
import org.apache.curator.RetryPolicy;
import org.apache.curator.RetrySleeper;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author joven_wong
 * 2021/6/29 16:02
 */
@Configuration
public class ZkConfig {

    @Autowired
    ZkProperties zkProperties;

    @Bean(initMethod = "start")
    public CuratorFramework curatorFramework(){
        return CuratorFrameworkFactory.newClient(
                zkProperties.getUri(), zkProperties.getSessionTimeoutMs(),
                zkProperties.getConnectionTimeoutMs(),
                new RetryNTimes(zkProperties.getMaxRetries(), zkProperties.getBaseSleepTimeMs())
        );
    }
}
